//
// Created by LiuYou on 2021/10/24.
//

#include <iostream>
#include <unistd.h>
#include <csignal>


static void signalHandler(int sig) {
    write( 1, "!", 1 );
}


int main(int argc, char** argv) {
//    signal( SIGINT, SIG_IGN);
    signal( SIGINT, signalHandler );

    sigset_t sigSet;
    sigset_t oldSigSet;
    sigset_t saveSet;
    sigemptyset( &sigSet );
    sigaddset( &sigSet, SIGINT );
    sigprocmask( SIG_UNBLOCK, &sigSet, &saveSet );
    for (int i = 0; i < 1000; ++i) {
        sigprocmask( SIG_BLOCK, &sigSet, &oldSigSet );
        for (int j = 0; j < 5; ++j) {
            write( 1, "*", 1 );
            sleep( 1 );
        }
        write( STDOUT_FILENO, "\n", 1 );
        sigprocmask( SIG_SETMASK, &oldSigSet, nullptr );
        pause();
    }

    sigprocmask( SIG_SETMASK, &saveSet, nullptr );



    return 0;
}
